/*
 * This file is part of the <a href="http://code.google.com/p/pux">PUX Framework</a>
 *
 * Copyright 2008-2009 by <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package de.teamskill.pux.library.gui;

import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JFrame;

import de.teamskill.pux.engine.Network;

/**
 * GUISupport
 * 
 * @author <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 * 
 */
public class GUISupport {

	private static final Map<Network, JFrame> frameMap = new HashMap<Network, JFrame>();

	/**
	 * getGUIFrame returns a (cached) JFrame instance for a given PUX network
	 * 
	 * @param network
	 * @return
	 */
	public static JFrame getGUIFrame(Network network) {
		synchronized (network) {
			JFrame f = frameMap.get(network);
			if (f == null) {
				f = createFrame(network);
				frameMap.put(network, f);
			}
			return f;
		}
	}

	/**
	 * createFrame
	 * 
	 * @param network
	 * @return
	 */
	private static JFrame createFrame(Network network) {
		JFrame f = new JFrame("PUX");
		f.getContentPane().setLayout(new BorderLayout());
		f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		return f;
	}

}
